#!/bin/bash
source /etc/profile

dt="`date -d "$d  0 days ago "  "+%Y-%m-%d"`"

#实时处理res_oil表
#sh /home/marvin/realtime_job/res_oil_select.sh |awk ' NR !=1 {print "INSERT into test.res_oil VALUES('\''"$1,$2"'\'',","'\''"$3"'\'',","'\''"$4"'\'',",$5,","$6,","$7") on duplicate key update oilNumber="$5",oilLitre="$6",oilMoney="$7";"}' >/home/marvin/realtime_job/mysql/res_oil_insert.sql && mysql -uroot  -proot </home/marvin/realtime_job/mysql/res_oil_insert.sql

#实时处理res_notoil表
#sh res_notoil_select.sh |awk ' NR !=1 {print "INSERT into test.res_notoil VALUES('\''"$1,$2"'\'',","'\''"$3"'\'',"$4",",$5") on duplicate key update notoilNumber="$4",notoilMoney="$5";"}'>/home/marvin/realtime_job/mysql/res_notoil_insert.sql && mysql -uroot  -proot </home/marvin/realtime_job/mysql/res_notoil_insert.sql

#实时处理res_addVip
#sh res_addvip_select.sh|awk ' NR !=1 {print "INSERT into test.res_addVip VALUES('\''"$1"'\'',"$2","$3") on duplicate key update number="$2",totalPeople="$3";"}'>/home/marvin/realtime_job/mysql/res_addvip_insert.sql && mysql -uroot  -proot</home/marvin/realtime_job/mysql/res_addvip_insert.sql
dt="`date -d "$d  0 days ago "  "+%Y-%m-%d"`"
yt="`date -d "$d  1 days ago "  "+%Y-%m-%d"`"
totalPeople="`mysql -uroot -proot  -e 'SELECT totalPeople from result.res_addVip where date="'"$yt"'"'|awk 'NR != 1 {print $1}'`"
echo totalPeople: $totalPeople
todayPeople="`mysql -uroot -proot -hhadoop2 -e 'SELECT COUNT(CARD_ID)AS COUNT FROM oracleanditem.TBL_CARD where EFFECTIVEDATE="'"$dt"'"' |awk 'NR !=1{print $1}'`"
if [ ! -n "$todayPeople" ] 
    then  todayPeople=0
fi
echo todayPeople: $todayPeople
totalPeople="`expr $totalPeople + $todayPeople`"
echo totalPeople: $totalPeople

mysql -uroot -proot -e "INSERT into test.res_addVip VALUES('$dt',$todayPeople,$totalPeople)"
echo "INSERT into test.res_addVip VALUES('$dt',$todayPeople,$totalPeople)"
#实时处理res_addVip_cd



